<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="支付类型" align="center" prop="type" width="80">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.PAY_TYPE" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="渠道编码" align="center" prop="code" width="150">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.PAY_CHANNEL_CODE" :value="scope.row.code" />
        </template>
      </el-table-column>
      <el-table-column label="配置信息" align="center" prop="code" min-width="200">
        <template #default="scope">
          <div class="multi-hidden">{{ scope.row.config || '无' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="sort" width="60" />
      <el-table-column label="开关" align="center" prop="enabled" width="60">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        v-hasRole="['super_admin']"
        align="center"
        width="60"
        fixed="right"
      >
        <template #default="scope">
          <el-button link type="danger" @click="openForm('update', scope.row.id)"> 编辑 </el-button>
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <PayChannelForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts" name="PayChannel">
import * as PayChannelApi from '@/api/pay/channel'
import PayChannelForm from './PayChannelForm.vue'
import { DICT_TYPE } from '@/utils/dict'

const loading = ref(true) // 列表的加载中
const list = ref<any>([]) // 列表的数据

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await PayChannelApi.getPayChannelList({})
    list.value = data
  } finally {
    loading.value = false
  }
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number | string) => {
  formRef.value.open(type, id)
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
